#include <graphics.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
char c;	

IMAGE img_bk;//背景
IMAGE img_bd1,img_bd2;//鸟

int position_x,position_y; //鸟位置
int score=0;//记录分数
int speed; //鸟下落速度



void start()
{
		//初始化
	initgraph(350,600);

	loadimage(&img_bd1,"E:\\bird1.jpg");
	loadimage(&img_bd2,"E:\\bird2.jpg");
	loadimage(&img_bk,"E:\\background.jpg");

	position_x = 130;
	position_y = 100;

	speed = 0;

    BeginBatchDraw();
}


void user()//用户输入
{
	if (kbhit())
	{
		c = getch();
		if (c == ' ')
			position_y = position_y - 50;

	}
}


void update ()
{
	//鸟下落
	speed ++;
	if (speed == 3){
		position_y ++;
		speed = 0;
	}

	//鸟落地扑街
	if (position_y > 590){
		outtextxy(140, 300, "GameOver!");
		EndBatchDraw();
		getch();
		closegraph();
	}



	

	



}


void show()
{


		putimage(0,0,&img_bk);//放置背景图


		putimage (position_x,position_y,&img_bd1,NOTSRCERASE);
		putimage (position_x,position_y,&img_bd2,SRCINVERT);//放置鸟






		outtextxy(200, 600*0.95, "得分：");
	    char s[5];
	    sprintf(s, "%d", score);
	    outtextxy(250, 600*0.95, s);
		
		FlushBatchDraw();
		Sleep(2);
		


}



int main()
{

    start();
	while (1)
	{
		user();
		update();
		show();
	}

	return 0;
}